import HTTP from '../util/http.js'

class BookModel extends HTTP { 
  getBookFavorNum() {
    return new Promise((resolve, reject) => {
      this.request('/api/favor/getBookFavorNum', {
        user: wx.getStorageSync('user').nickName 
      }).then((res) => {
        resolve(res)
      })
    })
  }

  getHotList(page = 1, pageSize = 20) {
    return new Promise((resolve, reject) => {
      this.request('/api/book/list', {
        page,
        pageSize 
      }).then((res) => {
        resolve(res)
      })
    })
  }

  getDetail(id) {
    return new Promise((resolve, reject) => {
      this.request('/api/book/detail', {
        id
      }).then((res) => {
        resolve(res)
      })
    })
  }

  getComments(id) {
    return new Promise((resolve, reject) => {
      this.request('/api/comment/list', {
        id
      }).then((res) => {
        resolve(res)
      })
    })
  }

  getLikeStatus(id) {
    return new Promise((resolve, reject) => {
      this.request('/api/book/favor', {
        id,
        user: wx.getStorageSync('user').nickName 
      }).then((res) => {
        resolve(res)
      })
    }) 
  }

  postComment(id, value) {
    return new Promise((resolve, reject) => {
      this.request('/api/comment/add', {
        id,
        value
      },'POST').then((res) => {
        resolve(res)
      })
    })
  }

  search(search, page, pageSize) {
    return new Promise((resolve, reject) => {
      this.request('/api/book/search', {
        search,
        page,
        pageSize 
      }).then((res) => {
        resolve(res)
      })
    })
  }

}

export {
  BookModel
}